package com.github.llyb120.undertaker;


import groovy.lang.Closure;

import java.util.LinkedList;
import java.util.Map;

public class groovy {

    static LinkedList<Object> stack = new LinkedList<>();

    public static void test(Closure closure){
        closure.call();
    }


    public static void api(String url, Closure closure){
        ApiContext apiContext = new ApiContext()
                .setUrl(url);
        stack.addLast(apiContext);
        closure.call();
        stack.removeLast();
    }


//    public static void putContext(Map<String, Object> map){
//        Object last = stack.getLast();
//        if(last instanceof ApiContext){
//            ApiContext apiContext = (ApiContext) last;
//        }
//    }

    public static void putContext(Closure closure){
        Object last = stack.getLast();
        if(last instanceof ApiContext){
            ApiContext apiContext = (ApiContext) last;
            apiContext.setPutContext(closure);
        }
    }


    public static void body(String str){

    }

    public static void query(Closure closure){

    }


    public static void repeat(int num){
        Object last = stack.getLast();
        if(last instanceof ApiContext){
            ApiContext apiContext = (ApiContext) last;
            apiContext.setRepeat(num);
        }
    }
}
